using System;
using System.Collections.Generic;
using System.Text;

namespace Xivo.Shared
{
  public class ChannelInfo : ICloneable
  {
    public enum UpdateType {
      shortName,
      longName
    }

    public UpdateType updateType;
    public int channel;
    public string channelStr
    {
      get
      {
        if (channel != 0)
          return channel.ToString();
        else
          return "";
      }
    }
    public bool valid;
    public string station;
    public string genre;
    public string longArtist;
    public string shortArtist;
    public string longTitle;
    public string shortTitle;

    public Object Clone()
    {
      ChannelInfo info = new ChannelInfo();
      info.valid = valid;
      info.channel = channel;
      info.station = station;
      info.genre = genre;
      info.shortArtist = shortArtist;
      info.shortTitle = shortTitle;
      info.longArtist = longArtist;
      info.longTitle = longTitle;
      return info;
    }

    public const int dataBlockSize = 128;
    public byte[] data = new byte[dataBlockSize];
    public byte[] GetDataBlock()
    {
      ASCIIEncoding.ASCII.GetBytes(channelStr,0,channelStr.Length,data,0);
      if (station != null)
        ASCIIEncoding.ASCII.GetBytes(station, 0, station.Length, data, 8);
      if (genre != null)
        ASCIIEncoding.ASCII.GetBytes(genre, 0, genre.Length, data, 24);
      if (longArtist != null)
        ASCIIEncoding.ASCII.GetBytes(longArtist, 0, longArtist.Length, data, 40);
      if (longTitle != null)
        ASCIIEncoding.ASCII.GetBytes(longTitle, 0, longTitle.Length, data, 56);
      data[126] = 0xc;
      data[127] = 0xa;
      return data;
    }

    public string getFileName()
    {
      string filename="";
      if (shortArtist != null && shortArtist != "")
        filename += shortArtist + "-";
      filename += shortTitle + " [" + DateTime.Now.ToString("MM-dd-yy HH-mm-ss") + "]" ;
      char[] invalidChars = System.IO.Path.GetInvalidFileNameChars();
      for (int pos = 0; pos < invalidChars.Length; ++pos)
        filename = filename.Replace(invalidChars[pos], '_');

      return filename;
    }

  }
}
